﻿using AjaxControlToolkit;
using ASP;
using IPMS.AccessAuth;
using IPMS.BLL;
using IPMS.Sort;
using IPMS.Common;
using System;
using System.Configuration;
using System.Globalization;
using System.IO;
using System.Text;
using System.Threading;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using Resources;
using System.Web;
using SysOperationLayer.DBHandle;
using System.Data;
using SysComm;


public partial class OptProjectGroupUpdate : Page, IRequiresSessionState
{
    LogDB m_logdb = new LogDB();
    ProjectGroupsDB m_projectgroupdb = new ProjectGroupsDB();


    protected override void InitializeCulture()
    {
        string sCulture = ConfigurationManager.AppSettings["DefaultCulture"].ToString();
        try
        {
            sCulture = this.Session["Culture"].ToString();
        }
        catch (NullReferenceException)
        {
        }
        Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(sCulture);
        Thread.CurrentThread.CurrentUICulture = new CultureInfo(sCulture);
        base.InitializeCulture();
    }


    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.Page.IsPostBack)
        {
            ((Label)this.Master.FindControl("lblMstTitle")).Text = "| " + ISitemap.ProjectGroupManage.ToString() + " | " + ISitemap.ProjectGroupUpdate.ToString();
            //加载下拉列表的值
            DataTable dt;
            CodeDB codedb = new CodeDB();
            ClientsDB clientdb = new ClientsDB();
            ProjectClassDB projectclassdb = new ProjectClassDB();
            ddlClient.Items.Clear();
            ddlProjectClass.Items.Clear();
            ddlType.Items.Clear();

            ddlClient.Items.Add(new ListItem(""));
            ddlProjectClass.Items.Add(new ListItem(""));
            ddlType.Items.Add(new ListItem(""));

            dt = codedb.getProjectTypeList();
            if (dt != null)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    ddlType.Items.Add(new ListItem(codedb.GetValue(dt.Rows[i], "Code")));
                }
            }
            dt = clientdb.getClientsList("", "", "", "", 0);
            if (dt != null)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    ddlClient.Items.Add(new ListItem(codedb.GetValue(dt.Rows[i], "Client")));
                }
            }
            dt = projectclassdb.getProjectClassList("", "", 0);
            if (dt != null)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    ddlProjectClass.Items.Add(new ListItem(codedb.GetValue(dt.Rows[i], "ProjectClass")));
                }
            }

            //加载project group
            string projectgroupid = Request["ProjectGroupID"].ToString();
            DataTable pgdt;

            pgdt = m_projectgroupdb.getProjectGroupsById(projectgroupid);

            if (pgdt != null)
            {
                this.txtProjectGroupID.Text = m_projectgroupdb.GetValue(pgdt.Rows[0], "ProjectGroupID");
                this.txtTitleSubject.Text = m_projectgroupdb.GetValue(pgdt.Rows[0], "TitleSubject");
                this.ddlType.SelectedValue = m_projectgroupdb.GetValue(pgdt.Rows[0], "Type");
                this.ddlProjectClass.SelectedValue = m_projectgroupdb.GetValue(pgdt.Rows[0], "ProjectClass");
                this.txtApplicant.Text = m_projectgroupdb.GetValue(pgdt.Rows[0], "Applicant");
                this.txtInventor.Text = m_projectgroupdb.GetValue(pgdt.Rows[0], "Inventor");
                this.ddlClient.SelectedValue = m_projectgroupdb.GetValue(pgdt.Rows[0], "Client");
                this.txtOfficerName.Text = m_projectgroupdb.GetValue(pgdt.Rows[0], "OfficerName");
                this.txtTitle.Text = m_projectgroupdb.GetValue(pgdt.Rows[0], "Title");
                this.txtOfficerRole.Text = m_projectgroupdb.GetValue(pgdt.Rows[0], "OfficerRole");
                this.txtOfficerEmail.Text = m_projectgroupdb.GetValue(pgdt.Rows[0], "OfficerEmail");
            }
        }
    }


    protected void btnSave_Click(object sender, EventArgs e)
    {
        int ret;
        ret = m_projectgroupdb.updateProjectGroup(txtProjectGroupID.Text.Trim(),
                                                    txtTitleSubject.Text.Trim(),
                                                    ddlType.SelectedItem.Text.Trim(),
                                                    ddlProjectClass.SelectedItem.Text.Trim(),
                                                    txtApplicant.Text.Trim(),
                                                    txtInventor.Text.Trim(),
                                                    ddlClient.SelectedItem.Text.Trim(),
                                                    txtOfficerName.Text.Trim(),
                                                    txtTitle.Text.Trim(),
                                                    txtOfficerRole.Text.Trim(),
                                                    txtOfficerEmail.Text.Trim());

        if (ret == 0)
        {
            m_logdb.writeSucLog(SysUtil.m_functiong_projectgroup, "update project group succeed!");
            Jscript.Alert("Update succeed!", this.Page);
        }
        else
        {
            m_logdb.writeFaileLog(SysUtil.m_functiong_projectgroup, "update project group failed!");
            Jscript.Alert("Update failed!", this.Page);
            lblError.Text = m_projectgroupdb.ErrorMessage;
        }
    }


    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("OptProjectGroups.aspx");
    }
}
